package _redis;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import java.io.*;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketException;

/**
 * @Author: huangya
 * @Date: 2020/1/7
 * @Description:
 */
public class _RedisConnection {

    public static void main(String[] args) throws IOException {
//        Socket socket = socket = new Socket();
//        socket.setReuseAddress(true);
//        socket.setKeepAlive(true); // Will monitor the TCP connection is
//        socket.setTcpNoDelay(true); // Socket buffer Whetherclosed, to
//        socket.setSoLinger(true, 0); // Control calls close () method,
//        socket.connect(new InetSocketAddress("localhost", 6379), 2000);
//        socket.setSoTimeout(2000);
//        OutputStream os = new DataOutputStream(socket.getOutputStream());
//        InputStream is = new DataInputStream(socket.getInputStream());
//
//
//
//        os.write(ASTERISK_BYTE);
//        writeIntCrLf(os, args.length + 1);
//        os.write(DOLLAR_BYTE);
//        os.writeIntCrLf(command.length);
//        os.write(command);
//        os.writeCrLf();
//
//        for (final byte[] arg : args) {
//            os.write(DOLLAR_BYTE);
//            os.writeIntCrLf(arg.length);
//            os.write(arg);
//            os.writeCrLf();
//        }
//
//        str.getBytes("UTF-8")

        File file = new File("F:\\111.txt");
        FileReader fis = new FileReader(file);
//        FileInputStream fis = new FileInputStream(file);
        FileWriter fos = new FileWriter("F:\\222.txt");
//        FileOutputStream fos = new FileOutputStream("F:\\222.txt");
//        byte[] bytes = new byte[1];
        char[] bytes = new char[1];
        int n;
        while((n=fis.read(bytes))>0){
            System.out.println(new String(bytes, 0, n));
            fos.write(bytes, 0, n);
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            fos.flush();
        }
        fos.close();
    }



//    public void writeIntCrLf(OutputStream outputStream, int value) throws IOException {
//        if (value < 0) {
//            outputStream.write((byte) '-');
//            value = -value;
//        }
//
//        int size = 0;
//        while (value > sizeTable[size])
//            size++;
//
//        size++;
//        if (size >= buf.length - count) {
//            flushBuffer();
//        }
//
//        int q, r;
//        int charPos = count + size;
//
//        while (value >= 65536) {
//            q = value / 100;
//            r = value - ((q << 6) + (q << 5) + (q << 2));
//            value = q;
//            buf[--charPos] = DigitOnes[r];
//            buf[--charPos] = DigitTens[r];
//        }
//
//        for (;;) {
//            q = (value * 52429) >>> (16 + 3);
//            r = value - ((q << 3) + (q << 1));
//            buf[--charPos] = digits[r];
//            value = q;
//            if (value == 0) break;
//        }
//        count += size;
//
//        writeCrLf();
//    }
}
